// 抽象产品类：AbstractProduct
abstract class AbstractProduct {
    // 可以添加一些抽象产品共有的方法
}

// 具体产品类：ConcreteProduct1
class ConcreteProduct1 extends AbstractProduct {
    // 实现具体产品1的方法
    public void operation() {
        System.out.println("ConcreteProduct1 operation");
    }
}

// 具体产品类：ConcreteProduct2
class ConcreteProduct2 extends AbstractProduct {
    // 实现具体产品2的方法
    public void operation() {
        System.out.println("ConcreteProduct2 operation");
    }
}

// 抽象工厂类：AbstractFactory
abstract class AbstractFactory {
    public abstract AbstractProduct createProduct1();
    public abstract AbstractProduct createProduct2();
}

// 具体工厂类：ConcreteFactory1
class ConcreteFactory1 extends AbstractFactory {
    @Override
    public AbstractProduct createProduct1() {
        return new ConcreteProduct1();
    }

    @Override
    public AbstractProduct createProduct2() {
        // 可以返回与ConcreteProduct1相关联的ConcreteProduct2
        return new ConcreteProduct2();
    }
}

// 具体工厂类：ConcreteFactory2
class ConcreteFactory2 extends AbstractFactory {
    @Override
    public AbstractProduct createProduct1() {
        return new ConcreteProduct1();
    }

    @Override
    public AbstractProduct createProduct2() {
        // 可以返回与ConcreteProduct1不同系列的ConcreteProduct2
        return new ConcreteProduct2();
    }
}

// 客户端代码
public class Client {
    private AbstractFactory factory;

    public Client(AbstractFactory factory) {
        this.factory = factory;
    }

    public void someOperation() {
        AbstractProduct product1 = factory.createProduct1();
        AbstractProduct product2 = factory.createProduct2();

        product1.operation();
        product2.operation();
    }

    public static void main(String[] args) {
        AbstractFactory factory1 = new ConcreteFactory1();
        Client client1 = new Client(factory1);
        client1.someOperation();

        AbstractFactory factory2 = new ConcreteFactory2();
        Client client2 = new Client(factory2);
        client2.someOperation();
    }
}